<?php $this->load->view('layout/lottery/header') ?>
<div class="lotteryMain">
	<ol class="breadcrumb">
		<li><a href="<?php echo site_url('lottery/winners'); ?>">中奖用户列表 </a></li>
		<li>中奖用户详情</li>
	</ol>
	<!-- <div class="panel-heading" id="winners-details">中奖用户详情 WINNING USER DETAILS</div> -->
	<!-- 虚拟物品 -->
	<?php $address = json_decode($winners->address); ?>
	<?php if ($winners->prize_type != 1) : ?>
	<div class="panel panel-default panel-detail panel-xuni">
		<div class="panel-heading" id="winners-details">中奖用户详情 WINNING USER DETAILS</div>
		<div class="panel-body">
	  		<div class="details">
				<p>
					<label class="control-label">中奖者</label>
					<span><?php echo mb_substr($winners->user_name, 0, 1), '***', mb_substr($winners->user_name, -1, 1); ?></span>
				</p>
				<p>
					<label class="control-label">中奖者信息</label>
					<span>
						<?php echo $address->receiver_name, '，', $address->tel; ?>
					</span>
				</p>
				<?php endif; ?>
				<p>
					<label class="control-label">奖品类型</label>
					<span><?php switch ($winners->prize_type) {
						case 2:
							echo '虚拟物品';
							break;
						case 3:
							echo '金币';
							break;
						case 4:
							echo '现场颁奖';
							break;
						default:
							echo '其它';
							break;
					} ?></span>
				</p>
				<p>
					<label class="control-label">奖品名称</label>
					<span><?php echo $winners->prize_name; ?></span>
				</p>
				<p>
					<label class="control-label">状态</label>
					<span>
						<?php switch ($winners->status) {
							case 1:
								echo ($winners->effective_date < date('Y-m-d H:i:s')) ? '已过期' : '未领奖';
								break;
							case 2:
								echo ($winners->effective_date < date('Y-m-d H:i:s')) ? '已过期' : '待处理';
								break;
							case 3:
								echo '处理完成';
								break;
							default:
								break;
						} ?>
					</span>
				</p>
				<p>
					<label class="control-label">奖品过期时间</label>
					<span><?php echo $winners->effective_date; ?></span>
				</p>
				<p>
					<label class="control-label">中奖时间</label>
					<span><?php echo $winners->created_at; ?></span>
				</p>
				<p>
					<label class="control-label">处理时间</label>
					<span><?php echo $winners->updated_at; ?></span>
				</p>
			</div>
			<div class="clearfix details-btns">
				<?php if ($winners->effective_date < date('Y-m-d H:i:s') || ($winners->status != 2)) : ?>
				<a href="<?php echo site_url('lottery/winners'); ?>" class="btn">返回</a>
				<?php else : ?>
				<a href="<?php echo site_url('lottery/virtualPrizes/'. $winners->id); ?>" class="btn" onclick="return confirm('确定该奖品已处理成功？')">确定已处理</a>
				<?php endif; ?>
			</div>
		</div>
	</div>
	<?php else: ?>
	<!-- 实物 -->
	<div class="panel-shiwu">
		<div class="panel panel-default panel-detail panel panel-default panel-detail panel-xuni">
			<div class="panel-heading" id="winners-details">中奖用户详情 WINNING USER DETAILS</div>
			<div class="panel-body">
				<div class="details-wrap clearfix">
			  		<div class="details">
						<p>
							<label class="control-label">中奖者</label>
							<span><?php echo mb_substr($winners->user_name, 0, 1), '***', mb_substr($winners->user_name, -1, 1); ?></span>
						</p>
						<?php if ( !empty($winners->address)) : ?>
						<?php $address = json_decode($winners->address); ?>
						<p>
							<label class="control-label">收货地址</label>
							<span>
								<?php echo $address->receiver_name, '，', $address->tel, '，', $address->code, '<br>', $address->detailed; ?>
							</span>
						</p>
						<?php endif; ?>
						<p>
							<label class="control-label">奖品名称</label>
							<span><?php echo $winners->prize_name; ?></span>
						</p>
						<p>
							<label class="control-label">奖品类型</label>
							<span>实物</span>
						</p>
						<p>
							<label class="control-label">状态</label>
							<span>
								<?php switch ($winners->status) {
									case 1:
										echo ($winners->effective_date < date('Y-m-d H:i:s')) ? '已过期' : '未领奖';
										break;
									case 2:
										echo ($winners->effective_date < date('Y-m-d H:i:s')) ? '已过期' : '待发货';
										break;
									case 3:
										echo '处理完成';
										break;
									default:
										break;
								} ?>
							</span>
						</p>
						<p>
							<label class="control-label">奖品过期时间</label>
							<span><?php echo $winners->effective_date; ?></span>
						</p>
						<p>
							<label class="control-label">中奖时间</label>
							<span><?php echo $winners->created_at; ?></span>
						</p>
						<p>
							<label class="control-label">处理时间</label>
							<span><?php echo $winners->updated_at; ?></span>
						</p>
					</div>
					<div class="express-state">
						<?php if ($winners->status == 1) : ?>
							<h4>奖品状态：未领奖</h4>
							<div class="state-detail">
							</div>
						<?php elseif ($winners->status == 2) : ?>
							<h4>奖品状态：待发货</h4>
							<a href="javascript:;" class="btn" data-toggle="modal" data-target="#myModal">填写运单号</a>
						<?php elseif ($winners->status == 3) : ?>
							<h4>发货状态：已发货，等待收货</h4>
							<div class="state-detail">
								<p class="orderNo">
									<span>物流：<?php echo $winners->name; ?></span> 
									<span>运单号：<?php echo $winners->number;?></span>
								</p>
							</div>
							<a href="javascript:;" class="btn" data-toggle="modal" data-target="#myModal">修改运单号</a>
						<?php endif; ?>
					</div>
				</div>
			</div>
		</div>
        <?php if ($winners->status == 3) : ?>
    	<?php $express = json_decode($winners->context); ?>
		<div class="panel panel-default panel-detail package-status">
			<div class="panel-heading">您的包裹状态</div>
			<div class="panel-body">
				<div class="status-box">
					<ul>
					<?php if( ! empty($express)) : ?>
					
						<?php $date = 0; ?>
						<?php foreach($express as $key=>$value) : ?>
						<li>
							<?php $date = ($date == substr($value->time, 0, 10)) ? '' : substr($value->time, 0, 10); ; ?>
							<span class="date"><?php echo ($date); ?></span>
							<span class="time"><?php echo substr($value->time, -8); ?></span>
							<span class="text"> <?php echo $value->context; ?></span>
						</li>
						<?php endforeach; ?>
					<?php else : ?>
                        <li>暂无物流信息</li>
                    <?php endif; ?>
                    </ul>
				</div>
			</div>
		</div>
		<?php endif; ?>
		<div class="clearfix details-btns">
			<a href="<?php echo site_url('lottery/winners'); ?>" class="btn">返回</a>
		</div>
	</div>
	<?php endif; ?>
</div>


<!-- Modal -->
<div class="modal fade modifyNo-modal" id="myModal" tabindex="-1" role="dialog">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel"><?php echo ($winners->status == 3) ? '修改运单号' : '填写运单号'; ?></h4>
			</div>
			<form class="form-horizontal" action="<?php echo site_url('lottery/updateWinners'); ?>" method="post" id="winners-express-form">
			<input type="hidden" name="id" value="<?php echo $winners->id; ?>">
			<div class="modal-body">
				<div class="alert alert-info" role="alert">
					<p><b>注意：</b>请确认无误后再发货。</p>
					<p>如果没有您需要选择的物流公司，请拨打400-0571-648，反馈于我们添加。谢谢！</p>
				</div>
				<div class="form-group clearfix">
					<label class="control-label">选择物流公司</label>
					<?php if ($expressAll->num_rows() > 0) : ?>
					<select class="txt" name="company" >
						<?php foreach($expressAll->result() as $value): ?>
						<option value="<?php echo $value->company; ?>"><?php echo $value->name; ?></option>
						<?php endforeach; ?>
					</select>
					<span class="error"></span>
					<?php endif; ?>
				</div>
				<div class="form-group clearfix">
					<label class="control-label">填写物流编号</label>
					<input type="text" class="form-control txt" name="express_num" />
					<span class="error"></span>
				</div>
			</div>
			<div class="modal-footer">
				<button type="submit" class="btn btn-primary">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
			</form>
		</div>
	</div>
</div>
<?php $this->load->view('layout/lottery/footer') ?>